<!DOCTYPE HTML>
<html>
<head>
    <title>安帮对象走访信息页面</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/default.css" rel="stylesheet" type="text/css"/>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
</head>
<div class="mini-fit" style="margin-bottom: 45px;width:100%;margin: 0 auto;">

    <form id="form1" method="post" style="padding-top: 10px;">
        <div align="left" style="width: auto;height:auto">
            <b style="font-size: 18px;">&nbsp;&nbsp;&nbsp;&nbsp;走访信息：</b>
        </div>
        <!-- 用户 编辑框START-->
        <div id="editform1" class="form" >
            <table style="padding-right: 300px;">
                <input id="priNum" name="priNum" class="mini-hidden" value="${priNum!''}" style="width: 100%;"  readonly/>
                <input id="pid" name="pid" class="mini-hidden" value="${pid!''}" style="width: 100%;"  readonly/>
                <input id="id" name="id" class="mini-hidden" value="${zfId!''}" style="width: 100%;"  readonly/>
                <input id="edit" name="edit" class="mini-hidden" value="${edit!''}" style="width: 100%;"  readonly/>
                <tr>
                    <td style="white-space:nowrap" align="right">姓名:</td>
                    <td>
                        ${prisonerBaseInfo.pname!''}
                    </td>
                </tr>
                <tr>
                    <td style="white-space:nowrap" align="right">身份号码:</td>
                    <td>
                        ${prisonerBaseInfo.idnum!''}
                    </td>
                </tr>
                <tr>
                    <td  style="line-height: 30px;width:15% " align="right"><font color="#dc143c">*</font>走访时间:</td>
                    <td style="line-height: 30px;width:20% ">
                        <input class="mini-datepicker" style="width: 100%" allowInput="false" value="${zoufangTime!''}" id="zoufangTime" name="zoufangTime" required="true" ondrawdate="onDrawDate"/>
                    </td>
                </tr>
                <tr>
                    <td   style="line-height: 30px;width:15% " align="right"><font color="#dc143c">*</font>走访人员:</td>
                    <td style="line-height: 30px;width:20% ">
                        <input name="zoufangPerson" id="zoufangPerson" class="mini-textbox"   value="${zoufangPerson!''}"
                               style="width: 100%" required="true"/></td>
                </tr>
                <tr>
                    <td  style="line-height: 30px;width:15% "align="right"><font color="#dc143c">*</font>走访单位:</td>
                    <td style="line-height: 30px;width:20% ">
                        <input name="zoufangDanwei" id="zoufangDanwei" class="mini-textbox"   value="${zoufangDanwei!''}"
                               style="width: 100%" required="true"/></td>
                </tr>
                <tr>
                    <td   style="line-height: 30px;width:15% " align="right">走访人员手机号码:</td>
                    <td style="line-height: 30px;width:20% ">
                        <input name="phone" id="phone" class="mini-textbox"   value="${phone!''}"
                               style="width: 100%" emptyText="请输入手机号码" onvaluechanged="checkPhone(2)"/></td>
                </tr>
                <tr>
                    <td  style="line-height: 30px;width:15% " align="right">走访人员固话:</td>
                    <td style="line-height: 30px;width:20% ">
                        <input name="telPhone" id="telPhone" class="mini-textbox"   value="${telPhone!''}"
                               style="width: 100%"  emptyText="请输入固定电话" onvaluechanged="checkPhone(1)"/></td>
                </tr>
                <tr>
                    <td   style="line-height: 30px;width:15% " align="right">帮教对象手机号码:</td>
                    <td style="line-height: 30px;width:20% ">
                        <input name="bjPhone" id="bjPhone" class="mini-textbox"   value="${bjPhone!''}"
                               style="width: 100%" emptyText="请输入手机号码" onvaluechanged="checkPhone(4)"/></td>
                </tr>
                <tr>
                    <td  style="line-height: 30px;width:15% " align="right">帮教对象固话:</td>
                    <td style="line-height: 30px;width:20% ">
                        <input name="bjTelPhone" id="bjTelPhone" class="mini-textbox"   value="${bjTelPhone!''}"
                               style="width: 100%"  emptyText="请输入固定电话" onvaluechanged="checkPhone(3)"/></td>
                </tr>
                <tr>
                    <td style="white-space:nowrap" align="right"><font color="#dc143c">*</font>走访内容:</td>
                    <td>
                    <textarea id="zoufangRemark" name="zoufangRemark" style="width: 100%;" class="mini-textarea"
                              emptyText="请输入走访内容" value="${zoufangRemark!''}" required="true"></textarea>
                    </td>
                </tr>
            </table>
            <!-- 用户 编辑框START-->
            <div id="fileform" class="form2" style="padding-left:130px">
                <table class="form-table"   width="100%">
                    <tr>
                        <td width="15%" align="right" style="line-height: 40px;">
                            附件上传:
                        </td>
                        <td >
                            <input type="button" value="上传附件" onclick="onFileUpload()">
<#--                            <span  style="color: #8B8B8B" >支持扩展名:.rar .zip .doc .docx .xls .xlsx .pdf .jpg...</span>-->
                            <span id="msg1"></span><br>
                            <span><b>支持扩展名:</b>.rar .zip .doc .docx .xls .xlsx .pdf .jpg</span>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </form>

</div>
<div style="position: absolute; bottom: 0;width:100%;border-top: 1px solid #dfdfdf;line-height: 45px;text-align: center">
    <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">保存</a>
    <a class="mini-button" iconCls="fa-undo" plain="true" onclick="close('close')">取消</a>
</div>
<script type="text/javascript">
    mini.parse();

    var priNumObj = mini.get("priNum");
    var editObj = mini.get("edit");
    var idObj = mini.get("id");
    var form = new mini.Form("form1");
    var phone = mini.get("phone");
    var telPhone = mini.get("telPhone");
    var bjTelPhone = mini.get("bjTelPhone");
    var bjPhone = mini.get("bjPhone");

    // 一打开页面
    window.onload = function (){
        $("#msg1").text("上传成功" + ${count1} + "条!")
    }

    function saveData() {
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var data = form.getData();
        var phone = data.phone;
        var telPhone = data.telPhone;
        var bjPhone = data.bjPhone;
        var bjTelPhone = data.bjTelPhone;
        var newPhone = checkTelAndPhone(telPhone,phone);
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if ('-1' === kflag) {
            mini.alert("请至少输入一个走访人员联系方式");
            return;
        }
        if (flag) {
        } else {
            mini.alert("走访人员手机号码或固话有误，请重填");
            return;
        }
        var newPhone2 = checkTelAndPhone(bjTelPhone,bjPhone);
        var flag = newPhone2['flag'];
        var kflag = newPhone2['kflag'];
        if ('-1' === kflag) {
            mini.alert("请至少输入一个帮教人员联系方式");
            return;
        }
        if (flag) {
        } else {
            mini.alert("帮教对象手机号码或固话有误，请重填");
            return;
        }
        data.pid = priNumObj.getValue();
        var json = mini.encode(data);
        data.edit = editObj.getValue();
        $.ajax({
            url: "/azbj/azbjgl/bjdxzf/saveBjZfInfo",
            type: "post",
            data: {data: json},
            success: function (result) {
                if(result.code == 1){
                    mini.alert("保存成功","成功",function(){
                        window.CloseOwnerWindow('ok');
                    });
                }
            }
        });
    }

    function close(action){
        if(window.CloseOwnerWindow){
            window.CloseOwnerWindow(action);
        }else{
            window.close();
        }
    }

    // 获取页面的id priNum等
    function GetData(){
        var idval = idObj.getValue();
        var priNum1 = priNumObj.getValue();
        var data = {priNum: priNum1, id: idval, taskId: '16'};
        return data;
    }

    <!-- 上传附件 -->
    function onFileUpload(e) {
        var idval = idObj.getValue();
        if(!idval){
            idval="noid";
        }
        var prival = priNumObj.getValue();
        // 走访附件task= 16
        var taskid = "16";
        var url = "/upload/user/uploadAppendixfile/view?1=1&id="+idval+"&priNum="+prival+"&taskId=" + taskid;
        commonEdit(url, null, null,600, 400, true,true,true,callback);
        // 回调函数
        function callback() {
            $.ajax({
                url: "/upload/downloadAppendixFile/getCountById?1=1&priNum="+prival+"&taskId=16" + "&id=" + idval,
                type: "get",
                success: function (success) {
                    $("#msg1").text("上传成功" + success.data + "条!");
                }
            })
            grid.reload();
        }
    }

    function checkPhone(e) {
        var phone = mini.get("phone").getValue();
        var telPhone = mini.get("telPhone").getValue();
        // 帮教人员联系电话
        var bjPhone = mini.get("bjPhone").getValue();
        // 帮教对象联系固话
        var bjTelPhone = mini.get("bjTelPhone").getValue();
        if (e == '1') {
            if (telPhone != '' && !/[0]\d{2,3}[-]?\d{7,8}/.test(telPhone)) {
                mini.alert('走访人员固定电话有误，请重填');
                return false;
            }
        }
        if (e == '2') {
            if (phone != '' && !(/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(phone))) {
                mini.alert("走访人员手机号码有误，请重填");
                return false;
            }
        }
        if(e == '3') {
            if (bjTelPhone != '' && !/[0]\d{2,3}[-]?\d{7,8}/.test(bjTelPhone)) {
                mini.alert('帮教对象固定电话有误，请重填');
                return false;
            }
        }
        if(e == '4') {
            if (bjPhone != '' && !(/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(bjPhone))) {
                mini.alert("帮教对象手机号码有误，请重填");
                return false;
            }
        }
    }

    /**
     * 解除时间禁止选择今天之后的日期
     * @param e
     */
    function onDrawDate(e) {
        var date = e.date;
        var d = new Date();
        if (date.getTime() > d.getTime()) {
            e.allowSelect = false;
        }
    }
</script>
</body>
</html>